package com.sumainfor.wx.tenant.service.impl;

import com.sumainfor.common.Constants;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ComUtils;
import com.sumainfor.common.utlis.ConvertDateTime;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.wx.tenant.entity.TctenSysmsg;
import com.sumainfor.wx.tenant.dao.TctenSysmsgMapper;
import com.sumainfor.wx.tenant.service.TctenSysmsgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author PuaChen
 * @since 2019-01-28
 */
@Service
public class TctenSysmsgServiceImpl extends ServiceImpl<TctenSysmsgMapper, TctenSysmsg> implements TctenSysmsgService {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log = LoggerFactory.getLogger(TctenSysmsgServiceImpl.class);
    @Autowired
    TctenSysmsgMapper tctenSysmsgMapper;

    /**
    * <p>
    * 新增
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult insertSysmsg(Map<String,Object> params) {
        JsonResult result = new JsonResult();
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            log.info("增加操作");
            params.put("term", "7");//创建端  1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
            params.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(params);
            Integer cout = tctenSysmsgMapper.insertSysmsg(params);
            if (cout <= 0) {
                result.putFailed("创建失败!");
            } else {

                result.putSuccess("创建成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事物回滚
            result.putFailed("服务器繁忙...");
        } finally {
            lock.unlock();
        }
        return result;
    }
}
